/*
 * RegEx.java
 * 
 * This file is part of Netuno Psamata.
 * 
 * CajuScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3, or (at your option) 
 * any later version.
 * 
 * CajuScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with CajuScript.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.netuno.psamata;

/**
 * Regular Expression.
 * @author eduveks
 */
public final class RegEx {
    /**
     * Regular Expression.
     */
    private RegEx() { }
    /**
     * To Regular Expression.
     * @param text Text
     * @return Text formatted in Relugar Expression
     */
    public static String toRegEx(final String text) {
        String r = "";
        if (text != null && !text.equals("")) {
            char[] chars = text.toCharArray();
            for (int x = 0; x < chars.length; x++) {
                String hex = Integer.toString(chars[x], 16);
                if (hex.length() == 1) {
                    hex = "0" + hex;
                }
                r += "\\x" + hex;
            }
        }
        return r;
    }
}
